<template>
    <div>
        <el-tree
                :data="regions"
                :props="props"
                node-key="name"
                :default-expanded-keys="submit_data[data.checkedKey]"
                show-checkbox
                @check-change="handleCheckChange"
                ref="tree">
                </el-tree>
    </div>
</template>
<script>
import Common from "./js/Common";
import * as Regions_ from "assets/region.json";
var Js = Common("sls-tree");
Js.mixins = [
  {
    data() {
      return {
        regions: [],
        props: {
          label: "name",
          children: "children"
        },
        subpros: ["310100", "110100", "120100", "500100"] //直辖市编码
      };
    },
    methods: {
      handleCheckChange(data, checked, indeterminate) {
        console.log("data,", data, checked, arguments);
        // let checkArea = (checked, value, province, city, area) => {
        //   if (checked) {
        //     let isExists = (() => {
        //       for (let key in this.submit_data[this.data.key]) {
        //         let addr = this.submit_data[this.data.key][key];
        //         if (addr.area == area && addr.city == city) {
        //           delete this.submit_data[this.data.key][key]["type"];
        //           return true;
        //         }
        //       }
        //       return false;
        //     })();
        //     if (!isExists) {
        //       this.submit_data[this.data.key].push({
        //         area: area,
        //         code: value,
        //         city: city,
        //         province: province,
        //         type: "add"
        //       });
        //     }
        //   } else {
        //     for (let key in this.submit_data[this.data.key]) {
        //       let addr = this.submit_data[this.data.key][key];
        //       if (addr.area == data.text && addr.city == data.parent.text) {
        //         if (!!addr.type && addr.type == "add") {
        //           this.submit_data[this.data.key].splice(key + 1);
        //         } else {
        //           this.submit_data[this.data.key][key]["type"] = "delete";
        //         }
        //         break;
        //       }
        //     }
        //   }
        // };
        // for (city in data.children) {
        //   if (this.subpros.indexOf(data.code) != -1) {
        //     let 
        //   } else {
        //     for (area in city.children) {
        //     }
        //   }
        // }
      },
      handleNodeClick(data) {
        console.log(data);
      },
      loadNode(node, resolve) {}
    },
    mounted() {
      this.regions = Regions_;
    }
  }
];
export default Js;
</script>
<style scoped lang="less"></style>